<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible" center width="60%">
        <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="180px">
        <#list fileds as param>
            <el-form-item label="${param.javaColumnName}：" prop="${param.javaColumnName}">
                <el-input v-model="dataForm.${param.javaColumnName}" placeholder="${param.columnComment}" clearable></el-input>
            </el-form-item>
        </#list>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
  import { ${beanName?uncap_first}One , ${beanName?uncap_first}Save } from '@/api/${beanName?uncap_first}'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          <#list fileds as param>
          ${param.javaColumnName}:null,
          </#list>
        },
        dataRule: {
        <#list fileds as param>
          ${param.javaColumnName}: [
            { required: true, message: '${param.columnComment}', trigger: 'blur' }
         ],
        </#list>
        }
      }
    },
    methods: {
      init (id) {
        if(id==null || id==undefined || id=="undefined"){
        <#list fileds as param>
          this.dataForm.${param.javaColumnName}=null
        </#list>
          this.visible = true
          return;
        }
        this.dataForm.id = id
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
        if(this.dataForm.id){
          const param= {
            'id': this.dataForm.id
          }
          const requestData={
            'requestData':param
          }
          ${beanName?uncap_first}One(requestData).then((res)=>{
            this.dataListLoading = false
            if(res.code=='0000'){
              this.dataForm= res.responseData
            }
          }).catch((err)=>{

          })
        }
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            const requestData={
              'requestData':this.dataForm
            }
            ${beanName?uncap_first}Save(requestData).then((res)=>{
            if(res.code=='0000'){
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            }
        }).catch((err)=>{

        })
        }
      })
      }
    }
}
</script>
